package view.console;

import java.rmi.AlreadyBoundException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import rmi.RemoteObserver;
import rmi.UtilitairesRmi;
import server.models.equipe.IEquipe;

public class ConsoleEquipeView implements RemoteObserver {

	private Console console = null;
	
	public ConsoleEquipeView(Console console, IEquipe equipe, String nomClient) {
		try {
			equipe.addObserver((RemoteObserver)UtilitairesRmi.getInstance().obtenirEtBind("ConsoleEquipeView_" + equipe.getNom() + "_" + nomClient, this));
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NotBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (AlreadyBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		this.console = console;
	}

	@Override
	public void update(Object equipe, Object arg1) {
		IEquipe equipeUpdate = (IEquipe)equipe;
		
		try {
			console.ajouterTexte(equipeUpdate.getNom() + " score : " + equipeUpdate.getScore());
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
